package org.apache.http.message;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HeaderIterator;
import org.apache.http.annotation.NotThreadSafe;

@NotThreadSafe
public class i implements Serializable, Cloneable {
    private final List a;

    public void a() {
        this.a.clear();
    }

    public void a(Header header) {
        if (header != null) {
            this.a.add(header);
        }
    }

    public void a(Header[] headerArr) {
        a();
        if (headerArr != null) {
            Collections.addAll(this.a, headerArr);
        }
    }

    public Header[] a(String str) {
        List arrayList = new ArrayList();
        for (int i = 0; i < this.a.size(); i++) {
            Header header = (Header) this.a.get(i);
            if (header.getName().equalsIgnoreCase(str)) {
                arrayList.add(header);
            }
        }
        return (Header[]) arrayList.toArray(new Header[arrayList.size()]);
    }

    public Header b(String str) {
        for (int i = 0; i < this.a.size(); i++) {
            Header header = (Header) this.a.get(i);
            if (header.getName().equalsIgnoreCase(str)) {
                return header;
            }
        }
        return null;
    }

    public void b(Header header) {
        if (header != null) {
            this.a.remove(header);
        }
    }

    public Header[] b() {
        return (Header[]) this.a.toArray(new Header[this.a.size()]);
    }

    public Header c(String str) {
        for (int size = this.a.size() - 1; size >= 0; size--) {
            Header header = (Header) this.a.get(size);
            if (header.getName().equalsIgnoreCase(str)) {
                return header;
            }
        }
        return null;
    }

    public HeaderIterator c() {
        return new g(this.a, null);
    }

    public void c(Header header) {
        if (header != null) {
            for (int i = 0; i < this.a.size(); i++) {
                if (((Header) this.a.get(i)).getName().equalsIgnoreCase(header.getName())) {
                    this.a.set(i, header);
                    return;
                }
            }
            this.a.add(header);
        }
    }

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public boolean d(String str) {
        for (int i = 0; i < this.a.size(); i++) {
            if (((Header) this.a.get(i)).getName().equalsIgnoreCase(str)) {
                return true;
            }
        }
        return false;
    }

    public HeaderIterator e(String str) {
        return new g(this.a, str);
    }

    public String toString() {
        return this.a.toString();
    }
}
